package org.argus.management.system.controller;

import org.argus.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.argus.management.domain.Menu;
import org.argus.management.system.model.MenuRoute;
import org.argus.management.system.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 刘文/Cliff Liu
 * @Date 2024/5/30
 */
@RestController
@RequestMapping("/system/v1/menu")
@Api(tags = "菜单管理")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/search")
    @ApiOperation("菜单查找")
    public R<List<Menu>> search(@RequestParam(name = "title", required = false) String title) {
        return R.ok(menuService.search(title));
    }

    @GetMapping("/user-menus")
    @ApiOperation("获取用户菜单")
    public R<List<MenuRoute>> getUserMenus() {
        return R.ok(menuService.getUserMenus());
    }

    @PostMapping
    @ApiOperation("菜单添加")
    public R<Boolean> add(@RequestBody Menu menu) {
        menuService.add(menu);
        return R.ok(Boolean.TRUE);
    }

    @PutMapping
    @ApiOperation("修改菜单")
    public R<Boolean> modify(@RequestBody Menu menu) {
        menuService.modify(menu);
        return R.ok(Boolean.TRUE);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除菜单")
    public R<Integer> delete(@PathVariable Long id) {
        return R.ok(menuService.delete(id));
    }

    @GetMapping("/role-menu")
    @ApiOperation("获取角色配置时的菜单列表")
    public R<List<Menu>> getRoleMenu() {
        return R.ok(menuService.getRoleMenu());
    }
}
